import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
// 封装state
function initialState(){
  return {
    token: localStorage.getItem('token') || '',
    username: localStorage.getItem('username') || ''
  }
}
export default new Vuex.Store({
  state: initialState(),
  mutations: {
    setToken(state,data){ //登录时存储token
      state.token = data;
      localStorage.setItem('token',data);
    },
    setUsername(state,data){ //登录时存储username
      state.username = data;
      localStorage.setItem('username',data);
    },
    resetState(state){ //重置state
      Object.assign(state,initialState());
    }
  },
  actions: {
  },
  modules: {
  }
})
